<?php

namespace App\Supports\Payment\Methods\Sandwap;

use Illuminate\Support\Facades\Log;
use App\Supports\Payment\Methods\Method;
use App\Supports\Payment\Contracts\MethodCallback;

class CallbackSandwap extends Method implements MethodCallback
{
	public function markAsPaid($order = null, $data = null) {}

	public function validate($data = null) {}

	protected function paidCallback($data)
	{
		$tag = $this->getPaidTag($data['tradeNo']);
		if ($tag == 'gold_charge') {
			return cashier('sandwap')->callbackGoldChargePay($data);
		}

		return 'fail';
	}


	public function callback($data = null)
	{
		$data = stripslashes(request('data'));
		$sign = request('sign');

		if (!$data or !$sign) return 'fail';

		$result = [
			'data' => $data,
			'sign' => $sign,
		];
		$verified = $this->channel->verify($result);

		$data = json_decode(request('data'), true);

		if ($verified and ($data['head']['respCode'] == '000000')) {
			return $this->paidCallback($data['body']);
		} else {
			return 'fail';
		}
	}
}
